<template>
  <el-dialog
    :close-on-click-modal="false"
    :visible="dialogVisible"
    title="入库管理"
    width="80%"
    :before-close="handleClose"
  >
    <vab-form-table
      v-model="KnifeInfoArray"
      drag
      :row-template="rowTemplate"
      style="width: 100%"
    >
      <el-table-column align="center" label="刀具编号" prop="ActionOrParam">
        <template #default="{ row }">
          <el-input v-model="row.Id" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="类型" prop="ActionOrParam">
        <template #default="{ row }">
          <el-input v-model="row.Type" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="直径" prop="RegisterAddress">
        <template #default="{ row }">
          <el-input v-model="row.Diameter" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="R角" prop="ReadOrWrite">
        <template #default="{ row }">
          <el-input v-model="row.Rangle" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="刃长" prop="ValueType">
        <template #default="{ row }">
          <el-input v-model="row.BladeLength" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="材质" prop="ValueType">
        <template #default="{ row }">
          <el-input v-model="row.Material" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="物料号" prop="ValueType">
        <template #default="{ row }">
          <el-input v-model="row.MaterialNo" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="报警阈值" prop="TrueValue">
        <template #default="{ row }">
          <el-input v-model="row.AlarmNum" disabled />
        </template>
      </el-table-column>
      <el-table-column align="center" label="位置" prop="TrueValue">
        <template #default="{ row }">
          <el-input v-model="row.Location" disabled />
        </template>
      </el-table-column>
      <el-table-column align="center" label="刀具名称" prop="TrueValue">
        <template #default="{ row }">
          <el-input v-model="row.Factory" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="刀长" prop="TrueValue">
        <template #default="{ row }">
          <el-input v-model="row.Contacts" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="刀柄" prop="TrueValue">
        <template #default="{ row }">
          <el-input v-model="row.ContactInformation" />
        </template>
      </el-table-column>
    </vab-form-table>
    <template slot="footer">
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <template>
          <el-button type="primary" @click="submit">确认</el-button>
        </template>
      </span>
    </template>
  </el-dialog>
</template>

<script>
  import { KnifeNewly } from '@/api/material'
  import VabFormTable from '@/extra/VabFormTable'
  export default {
    components: {
      VabFormTable,
    },
    data() {
      return {
        rowTemplate: {
          Id: '',
          Type: '',
          Diameter: '',
          Rangle: '',
          BladeLength: '',
          Material: '',
          MaterialNo: '',
          AlarmNum: '0',
          Location: '0',
          Factory: '',
          Contacts: '',
          ContactInformation: '',
        },
        KnifeInfoArray: [],
        dialogVisible: false,
      }
    },
    mounted() {},
    methods: {
      show() {
        this.dialogVisible = true
      },
      handleClose() {
        this.dialogVisible = false
      },
      submit() {
        let status = false
        const data = this.KnifeInfoArray.map((v) => {
          for (let k in v) {
            if (!v[k]) status = true
          }
        })
        if (status) {
          this.$baseMessage('请填写完整信息', 'error', 'vab-hey-message-error')
          return false
        }

        KnifeNewly({ KnifeInfoArray: this.KnifeInfoArray }).then((res) => {
          this.$baseMessage('成功', 'success', 'vab-hey-message-success')
          this.KnifeInfoArray = []
          this.dialogVisible = false
          this.$emit('fetch-data')
        })
      },
    },
  }
</script>

<style lang="scss" scoped></style>
